package com.advertisementsystem.adservice.controller;

import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/health")
public class HealthController {

    @Autowired(required = false)
    private FastFileStorageClient storageClient;

    @GetMapping("/fastdfs")
    public ResponseEntity<String> checkFastDFS() {
        if (storageClient == null) {
            return ResponseEntity.status(503).body("FastDFS客户端未配置");
        }

        try {
            // 尝试执行一个简单的操作来测试连接
            // 这里只是检查Bean是否存在，实际测试可能需要更复杂的方法
            return ResponseEntity.ok("FastDFS客户端已就绪");
        } catch (Exception e) {
            return ResponseEntity.status(503).body("FastDFS连接失败: " + e.getMessage());
        }
    }
}